package com.example.permission.mybatis;

import org.mybatis.generator.api.IntrospectedColumn;
import org.mybatis.generator.api.dom.java.FullyQualifiedJavaType;
import org.mybatis.generator.internal.types.JavaTypeResolverDefaultImpl;

/**
 * Mybatis - 重载生成代码工具的方法, 可以自定义长度与java类之间的对应
 *                       
 * @Filename: mybatisGenerator.java
 * @Version: 1.0
 * @Author: peter朱硕磊
 * @Email: 455474281@qq.com
 *
 */
public class JavaTypeGenerator extends JavaTypeResolverDefaultImpl {
    private int num1 = 18, num2 = 9, num3 = 4;

    @Override
    public FullyQualifiedJavaType calculateBigDecimalReplacement(IntrospectedColumn column,
                                                                 FullyQualifiedJavaType defaultType) {
        FullyQualifiedJavaType answer;

        if (column.getScale() > 0 || column.getLength() > num1 || forceBigDecimals) {
            answer = defaultType;
        } else if (column.getLength() > num2) {
            answer = new FullyQualifiedJavaType(Long.class.getName());
        } else if (column.getLength() > num3) {
            answer = new FullyQualifiedJavaType(Integer.class.getName());
        } else {
            answer = new FullyQualifiedJavaType(Integer.class.getName());
            //answer = new FullyQualifiedJavaType(Double.class.getName());
        }

        return answer;
    }

}
